home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java Primer Plus
/
Java Primer Plus (Waite Group Proess)(1996).iso
/
chapter10
/
dynamic.java
< prev
next >
Wrap
Text File
|
1995-12-31
|
673b
|
33 lines
/* Dynamic Instantiation example */
class Shape {}
class rectangle extends Shape {
rectangle() {
System.out.println("rectangle instantiated");
}
}
class circle extends Shape {
circle() {
System.out.println("circle instantiated");
}
}
class triangle extends Shape {
triangle() {
System.out.println("triangle instantiated");
}
}
/* Create a rectangle object "on the fly" */
class dynamic {
static public void main(String args[]) throws
ClassNotFoundException,
InstantiationException,
IllegalAccessException {
String S = "rectangle";
Shape myShape = (Shape)Class.forName(S).newInstance();
}
}